package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.FmsType;
import com.ruoyi.system.service.IFmsTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 财务类型Controller
 * 
 * @author ruoyi
 * @date 2023-12-31
 */
@RestController
@RequestMapping("/system/type")
@RequiredArgsConstructor
public class FmsTypeController extends BaseController
{
    private final IFmsTypeService fmsTypeService;
    /**
     * 查询所有财务类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/listAll")
    public AjaxResult getAllType() {
        return AjaxResult.success("获取类型数据成功",fmsTypeService.selectFmsTypeAllList());
    }
    /**
     * 查询财务类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(FmsType fmsType)
    {
        startPage();
        List<FmsType> list = fmsTypeService.selectFmsTypeList(fmsType);
        return getDataTable(list);
    }

    /**
     * 导出财务类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "财务类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmsType fmsType)
    {
        List<FmsType> list = fmsTypeService.selectFmsTypeList(fmsType);
        ExcelUtil<FmsType> util = new ExcelUtil<FmsType>(FmsType.class);
        util.exportExcel(response, list, "财务类型数据");
    }

    /**
     * 获取财务类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fmsTypeService.selectFmsTypeById(id));
    }

    /**
     * 新增财务类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "财务类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmsType fmsType)
    {
        fmsType.setCreateBy(getUsername());
        return toAjax(fmsTypeService.insertFmsType(fmsType));
    }

    /**
     * 修改财务类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "财务类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmsType fmsType)
    {
        return toAjax(fmsTypeService.updateFmsType(fmsType));
    }

    /**
     * 删除财务类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "财务类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fmsTypeService.deleteFmsTypeByIds(ids));
    }
}
